using System;
using System.Data;
using System.Data.SqlClient;

using PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;

namespace PHSRAG.Insight21.ClinicalTrials
{
   /// <summary>
   /// The BudgetExpense class is the facade over a single Budget Expense
   /// </summary>
   public class BudgetExpense : BusinessObject
   {

      #region Constants
      private const string BudgetExpenseKey = "BudgetExpense_71447D24-4FAF-4c3f-A10B-44C62C2BF368";
      private const string TableName = "BudgetExpense";
      #endregion

      #region Instance Variables
      private DataRow dataRow;
      #endregion

      #region Public Properties
      /// <summary>
      /// Unique Id for this Budget Expense
      /// </summary>
      public int Id
      {
         get
         {
            object o = dataRow["Id"];
            return (o == DBNull.Value) ? 0 : (int)o;
         }
      }

      /// <summary>
      /// Id of the Budget that this Expense is related to
      /// </summary>
      public int BudgetId
      {
         get
         {
            return (int)dataRow["ClinicalTrialBudgetId"];
         }
         set
         {
            dataRow["ClinicalTrialBudgetId"] = value;
         }
      }

      /// <summary>
      /// Study Cost Code
      /// </summary>
      public string StudyCostCode
      {
         get
         {
            return dataRow["StudyCostCode"].ToString( );
         }
         set
         {
            dataRow["StudyCostCode"] = value;
         }
      }

      /// <summary>
      /// Other expense cost.  Used when Study Cost Code is "Other"
      /// </summary>
      public string OtherExpenseText
      {
         get
         {
            object o = dataRow["OtherExpenseText"];
            return ( o == DBNull.Value ) ? null : o.ToString( );
         }
         set
         {
            dataRow["OtherExpenseText"] = value;
         }
      }

      /// <summary>
      /// Expense Cost
      /// </summary>
      public string ExpenseCost
      {
         get
         {
            object o = dataRow["ExpenseCost"];
            return ( o == DBNull.Value ) ? null : o.ToString( );
         }
         set
         {
            dataRow["ExpenseCost"] = value;
         }
      }

      /// <summary>
      /// Boolean indicating whether to apply overhead to this expense
      /// </summary>
      public bool ApplyOverhead
      {
         get
         {
            object o = dataRow["ApplyOverhead"];
            return ( o == DBNull.Value ) ? false : (bool)o;
         }
         set
         {
            dataRow["ApplyOverhead"] = value;
         }
      }

      /// <summary>
      /// Boolean indicating whether this expense is a variable cost.  Variable costs
      /// are similar to regular expenses, but are separated for the purposes of display
      /// and reporting.
      /// </summary>
      public bool VariableCost
      {
         get
         {
            object o = dataRow["VariableCost"];
            return ( o == DBNull.Value ) ? false : (bool)o;
         }
         set
         {
            dataRow["VariableCost"] = value;
         }
      }
      #endregion

      #region Constructor
      /// <summary>
      /// Initialize the base class with the specified cache policy and sets the dataRow member.
      /// </summary>
      public BudgetExpense( ICachePolicy cachePolicy, DataRow row ) : base ( cachePolicy )
      {
         dataRow = row;
      }
      #endregion

      #region Base Methods
      /// <summary>
      /// Cache this instance using the prevalent cache policy.
      /// </summary>
      public override void Cache( )
      {
         CachePolicy.Cache( BudgetExpenseKey, this );
      }

      /// <summary>
      /// Remove this instance from the cache using the prevalent cache policy.
      /// </summary>
      public override void UnCache( )
      {
         CachePolicy.UnCache( BudgetExpenseKey );
      }

      /// <summary>
      /// Load method is not used
      /// </summary>
      /// <param name="connectionString"></param>
      /// <param name="args"></param>
      public override void Load( string connectionString, params object[] args )
      {
         throw new Exception("BudgetExpense is not directly loadable");
      }
      #endregion

   }// END CLASS DEFINITION BudgetExpense
}